﻿using System;
using System.Collections.Generic; 

namespace Titan.ExpressionAnalyse
{
    public class SqlAnalyseResult
    {

        public SqlAnalyseResult()
        {
            this.SqlColumns = new Dictionary<string, SqlColumn>(StringComparer.OrdinalIgnoreCase);
            this.SortedOutputSqlColumns = new List<OutputSqlColumn>();
            this.ForeignTables = new List<SqlTable>();
            this.ObjectFiller = new ObjectFiller();
        }

        /// <summary>
        /// 以属性的全路径作为键，例如"Person.City.CityName"
        /// </summary> 
        private Dictionary<string, SqlColumn> SqlColumns { get; set; }

        public void AddSqlColumn(SqlColumn sqlColumn)
        {
            SqlColumns.Add(Util.ToGroupPropertyKey(sqlColumn.FullPropertyName, sqlColumn.GroupFunction), sqlColumn);
        }
        public SqlColumn GetSqlColumn(string fullPropertyName,GroupFunction groupFunction)
        {
            return SqlColumns[Util.ToGroupPropertyKey(fullPropertyName, groupFunction)];
        }
         
        /// <summary>
        /// 按outputColumnIndex排序的，因为在字段输出时需要
        /// 只会在拼接select部分的时候用到
        /// </summary>
        public List<OutputSqlColumn> SortedOutputSqlColumns { get; set; } 


        /// <summary>
        /// 主表的配型
        /// </summary>
        public EntityType MasterEntityType { get; set; }

        /// <summary>
        /// 主表的别名，如"t1"
        /// </summary>
        public string MasterTableNameAlias { get; set; }

         
        public List<SqlTable> ForeignTables { get; set; }

         
        public ObjectFiller ObjectFiller { get; set; }


        /// <summary>
        /// 是否有汇总函数
        /// </summary>
        public bool HasGroup { get; set; }
    }
}
